package one.stand.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import one.stand.aop.ApiController;
import one.stand.model.ResultModel;
import one.stand.request.TokenRequest;
import one.stand.request.UserLevelRequest;
import one.stand.response.UserLevelResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 分销管理
 *
 * @author: ZRH
 * @CreateDate: 2019/6/20 9:59
 */
@RestController
@RequestMapping("userApi/distribution")
@Api("分销管理")
public class DistributionController extends BaseController{

    @PostMapping("/insertUserLevel")
    @ApiOperation(value = "申请成为分销员（3.2版本迭代）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "公司id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true, paramClass = UserLevelRequest.class)
    public ResultModel<String> insertUserLevel(@RequestAttribute UserLevelRequest request) {
        return userFegin.insertUserLevel(request);
    }

    @PostMapping("/getUserLevelInfo")
    @ApiOperation(value = "分销员中心（3.2版本迭代）")
    @ApiController(isLogin = true, isParam = false)
    public ResultModel<Map<String, Object>> getUserLevelInfo(@RequestAttribute TokenRequest tokenRequest) {
        UserLevelRequest request=new UserLevelRequest();
        BeanUtils.copyProperties(tokenRequest,request);
        return userFegin.getUserLevelInfo(request);
    }

    @PostMapping("/saveInvitationCard")
    @ApiOperation(value = "生成邀请卡")
    @ApiController(isLogin = true, isParam = false)
    public ResultModel<Map<String, Object>> saveInvitationCard(@RequestAttribute UserLevelRequest request) {
        return userFegin.saveInvitationCard(request);
    }

    @PostMapping("/saveDistributor")
    @ApiOperation(value = "邀请存为分销员(扫码进入)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "邀请id", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true, isParam = false)
    public ResultModel<Boolean> saveDistributor(@RequestAttribute UserLevelRequest request) {
        return userFegin.saveDistributor(request);
    }

    @PostMapping("/myInvitationList")
    @ApiOperation(value = "我的邀请列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "days", value = "时间查询", paramType = "Integer"),
    })
    @ApiController(isLogin = true, isParam = false)
    public ResultModel<Map<String, Object>> myInvitationList(@RequestAttribute UserLevelRequest request) {
        return userFegin.myInvitationList(request);
    }

    @PostMapping("/applyBusinessList")
    @ApiOperation(value = "推广商家列表")
    @ApiController(isLogin = true, isParam = false)
    public ResultModel<Map<String, Object>> applyBusinessList(@RequestAttribute UserLevelRequest request) {
        return userFegin.applyBusinessList(request);
    }

    @PostMapping("/distributorOrderList")
    @ApiOperation(value = "推广订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "公司id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "days", value = "时间查询", paramType = "Integer"),
    })
    @ApiController(isLogin = true, isParam = false)
    public ResultModel<List<UserLevelResponse>> distributorOrderList(@RequestAttribute UserLevelRequest request) {
        return userFegin.distributorOrderList(request);
    }
}
